package com.cipta.lomob.adapter;

import java.util.LinkedList;

import com.cipta.lomob.R;
import com.cipta.lomob.model.ItemProfile;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ItemProfileAdapter extends BaseAdapter{
	Activity activity;
	LinkedList<ItemProfile> listItem;
	LayoutInflater inflater;
	
	public ItemProfileAdapter(Activity activity, LinkedList<ItemProfile> listItem) {
		// TODO Auto-generated constructor stub
		this.activity = activity;
		this.listItem = listItem;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listItem.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View view = arg1;
		ViewHolder holder = null;
		
		if (view == null) {
			view = inflater.inflate(R.layout.inf_item_profile, null);
			holder = new ViewHolder();
			holder.txtTitle = (TextView)view.findViewById(R.id.inf_txt_item_profile_title);
			holder.txtComments = (TextView)view.findViewById(R.id.inf_txt_item_profile_comments);
			holder.txtIsLive = (TextView)view.findViewById(R.id.inf_txt_item_profile_is_live);
			holder.txtLoves = (TextView)view.findViewById(R.id.inf_txt_item_profile_total_love);
			holder.txtWatching = (TextView)view.findViewById(R.id.inf_txt_item_profile_total_watch);
			holder.imgItem = (ImageView)view.findViewById(R.id.inf_img_item_profile);
			view.setTag(holder);
		} else {
			holder = (ViewHolder)view.getTag();
		}
		
		holder.txtIsLive.setVisibility(View.VISIBLE);
		
		holder.txtComments.setText("Comments "+listItem.get(arg0).getComments());
		if (listItem.get(arg0).getIsLive().equals("true")) {
			holder.txtIsLive.setText("Live");
		} else {
			holder.txtIsLive.setVisibility(View.GONE);
		}
		holder.txtLoves.setText(listItem.get(arg0).getLikes());
		holder.txtTitle.setText(listItem.get(arg0).getTitle());
		holder.txtWatching.setText("Watching "+listItem.get(arg0).getWatching());
		holder.imgItem.setImageResource(listItem.get(arg0).getThumbnail());
		
		return view;
	}
	
	static class ViewHolder{
		ImageView imgItem;
		TextView txtTitle, txtLoves, txtComments, txtWatching, txtIsLive;
	}
}
